package com.ddd.framework.dto;

import com.ddd.framework.enums.ResponseCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;
import java.util.Collection;

/**
 * MultiResponse
 *  Response with batch record to return, usually use in conditional query
 * @author guowm
 * @date 2025-02-08
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class MultiResponse<T> extends Response {
    @Serial
    private static final long serialVersionUID = 1L;

    private Collection<T> data;

    public boolean isEmpty() {
        return data == null || data.isEmpty();
    }

    public boolean isNotEmpty() {
        return !isEmpty();
    }

    public static <T> MultiResponse<T> success(Collection<T> data) {
        MultiResponse<T> response = new MultiResponse<>();
        response.setCode(ResponseCode.SUCCESS.getCode());
        response.setData(data);
        return response;
    }

}
